package org.yu.team2023.flashdays.item;

import lombok.Getter;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.yu.team2023.flashdays.TreasureQuality;
import org.yu.team2023.flashdays.TreasureSets;

public class UnidentifiedTreasure extends Item {

    @Getter
    final TreasureSets treasure;
    @Getter
    private final TreasureQuality quality;

    public UnidentifiedTreasure(Properties pProperties, TreasureSets treasure, TreasureQuality quality) {
        super(pProperties);
        this.treasure = treasure;
        this.quality = quality;
    }

    @Override
    public InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, Player pPlayer, @NotNull InteractionHand pUsedHand) {
        var stack = pPlayer.getItemInHand(pUsedHand);
        var index=pLevel.random.nextInt(4);
        pPlayer.addItem(TreasureCurios.newInstance(treasure.indexBy(index), quality,index));
        stack.shrink(1);
        return InteractionResultHolder.success(stack);
    }
}
